<?php require_once('../Connections/miportal.php'); ?>
<?php require_once('../Connections/miportal.php'); ?>
<?php require_once('../Connections/miportal.php'); 
mysql_query("SET NAMES 'utf8'");?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "../private/login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../private/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
mysql_select_db($database_miportal, $miportal);
$query_rsGiro = "SELECT * FROM cat_giro ORDER BY id_giro ASC";
$rsGiro = mysql_query($query_rsGiro, $miportal) or die(mysql_error());
$row_rsGiro = mysql_fetch_assoc($rsGiro);
$totalRows_rsGiro = mysql_num_rows($rsGiro);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formUpdateEmpresa")) {
  $updateSQL = sprintf("UPDATE cat_empresa SET id_cat_entidad=%s, id_cve_rfc=%s, id_nom_fiscal=%s, nb_nomComercial=%s, gf_municipio=%s, if_localidad=%s, id_direccion=%s, if_cpostal=%s, tx_actFiscal=%s, id_giro=%s WHERE id_cat_empresa=%s",
                       GetSQLValueString($_POST['insEntidad'], "text"),
                       GetSQLValueString($_POST['insRFC'], "text"),
                       GetSQLValueString($_POST['insRazon_social'], "text"),
                       GetSQLValueString($_POST['insNombre_comercial'], "text"),
                       GetSQLValueString($_POST['insMunicipio'], "text"),
                       GetSQLValueString($_POST['insLocalidad'], "text"),
                       GetSQLValueString($_POST['insDireccion'], "text"),
                       GetSQLValueString($_POST['insCP'], "text"),
                       GetSQLValueString($_POST['insActividad'], "text"),
                       GetSQLValueString($_POST['ins_giro'], "int"),
                       GetSQLValueString($_POST['id_cat_empresa'], "int"));

  mysql_select_db($database_miportal, $miportal);
  $Result1 = mysql_query($updateSQL, $miportal) or die(mysql_error());

  $updateGoTo = "../report/report_dve_empresa.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsEmpresa = "-1";
if (isset($_GET['id_cat_empresa'])) {
  $colname_rsEmpresa = base64_decode($_GET['id_cat_empresa']);
}
mysql_select_db($database_miportal, $miportal);
$query_rsEmpresa = sprintf("SELECT * FROM cat_empresa WHERE id_cat_empresa = %s", GetSQLValueString($colname_rsEmpresa, "text"));
$rsEmpresa = mysql_query($query_rsEmpresa, $miportal) or die(mysql_error());
$row_rsEmpresa = mysql_fetch_assoc($rsEmpresa);
$totalRows_rsEmpresa = mysql_num_rows($rsEmpresa);

$colname_rsMunicipio = "-1";
if (isset($row_rsEmpresa['id_cat_entidad'])) {
  $colname_rsMunicipio = $row_rsEmpresa['id_cat_entidad'];
}
mysql_select_db($database_miportal, $miportal);
$query_rsMunicipio = sprintf("SELECT id_cat_entidad, id_cat_municipio, nb_nomMun FROM cat_municipio WHERE id_cat_entidad = %s ORDER BY nb_nomMun ASC", GetSQLValueString($colname_rsMunicipio, "text"));
$rsMunicipio = mysql_query($query_rsMunicipio, $miportal) or die(mysql_error());
$row_rsMunicipio = mysql_fetch_assoc($rsMunicipio);
$totalRows_rsMunicipio = mysql_num_rows($rsMunicipio);


?>
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximun-scale=1">
<title>FUNDACIÓN EDUCACIÓN SUPERIOR-EMPRESA</title>
<!--Hoja de estilo principal-->
<link href="../css/styletd2.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="shortcut icon" href="stylesheet/img/devil-icon.png"> 
<link rel="stylesheet" type="text/css" href="../css/mos-style.css">
<link rel="stylesheet" type="text/css" href="../css/menu.css"><!--Pemanggilan gambar favicon-->
 <!--pemanggilan file css-->
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="../SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<link href="../SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css">
<script language=""="JavaScript">
	function conMayusculas(field) {
				field.value = field.value.toUpperCase()
		}
			function incubadora(val) {
				documen.write(val);
		}
	function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}

	function confirmar ( mensaje ) {
					return confirm( mensaje );
				}
        </script>
<script><!--SCRIPT AJAX MUNICIPIO EDIT-->
	function showMunicipio(str)
	{
		if (str=="")
		  {
		  document.getElementById("municipio").innerHTML="";
		  return;
		  } 
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  	  }
		xmlhttp.onreadystatechange=function()
		  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				document.getElementById("municipio").innerHTML=xmlhttp.responseText;
			}
	  }
	xmlhttp.open("GET","../lib/utils/getMunicipio.php?q="+str,true);
	xmlhttp.send();
	}
</script>
</head>
<body>

<div id="background">
</div>

 
<header>
        <div id="background"></div><!--BackGround Menu header-->
		<div class="img_header_logo"></div>
  <span class="img_header_logo"><a href="http://fese.org.mx"><img src="../images/fese/FESE_home_logo.png"  height="90" alt="FESE" align="bottom" /></a></span>
		<div class="img_header_logo"></div>
		<?php include_once('../include/dir_dve_nav.php');?>
</header>

<center>
<div id="boxcontainer">

<div id="container">
<hr>

<h2>EDICIÓN DE EMPRESA</h2>
<form action="<?php echo $editFormAction; ?>" method="POST" name="formUpdateEmpresa">
<table name="t_candidato" width="720px" border="1">
	<tr>
		<td colspan="2"><h3>INFORMACIÓN FISCAL 
		  <input name="id_cat_empresa" type="hidden" id="id_cat_empresa" value="<?php echo $row_rsEmpresa['id_cat_empresa']; ?>">
		</h3></td>
		</tr>
	<tr>
		<td>RFC</td>
		<td><span id="sprytextfield1">
        <input name="insRFC" type="text" id="insRFC" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['id_cve_rfc']; ?>">
        <br>
        <span class="textfieldRequiredMsg">Se necesita un valor.</span><span class="textfieldMinCharsMsg">No se cumple el mínimo de caracteres requerido.</span><span class="textfieldMaxCharsMsg">Se ha superado el número máximo de caracteres.</span></span></td>
	</tr>
	<tr>
		<td>Nombre, denominación o razón social*</td>
		<td ><span id="rozon_social">
		  <input name="insRazon_social" type="text" id="insRazon_social" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['id_nom_fiscal']; ?>">
		  <br>
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
		<td>Nombre comercial</td>
		<td><span id="nombre_comercial">
		  <input name="insNombre_comercial" type="text" id="insNombre_comercial" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['nb_nomComercial']; ?>">
		  <br>
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
		<td>Actividad </td>
		<td><span id="actividad">
		  <input name="insActividad" type="text" id="insActividad" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['tx_actFiscal']; ?>">
		  <br>
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
    <td>Giro*</td>
		<td width="320"><span id="giro">
		  <select name="ins_giro" id="ins_giro" style="width:280px">
		    <option value=""></option>
		    <?php
do {  
?>
		    <option value="<?php echo $row_rsGiro['id_giro']?>" <?php if (!(strcmp($row_rsGiro['id_giro'], $row_rsEmpresa['id_giro']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsGiro['nb_nomDesc']?></option>
		    <?php
} while ($row_rsGiro = mysql_fetch_assoc($rsGiro));
  $rows = mysql_num_rows($rsGiro);
  if($rows > 0) {
      mysql_data_seek($rsGiro, 0);
	  $row_rsGiro = mysql_fetch_assoc($rsGiro);
  }
?>
		    </select>
		  <span class="selectRequiredMsg">Seleccione un elemento.</span></span>
    </td>
	<tr>
	<td>Entidad Federativa</td>
		<td><span id="entidad">
		  <select name="insEntidad" id="insEntidad"  onChange="showMunicipio(this.value)">
		    <option value="" <?php if (!(strcmp("", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>Seleccione</option>
		    <option value="01" <?php if (!(strcmp("01", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>AGUASCALIENTES</option>
		    <option value="02" <?php if (!(strcmp("02", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>BAJA CALIFORNIA</option>
		    <option value="03" <?php if (!(strcmp("03", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>BAJA CALIFORNIA SUR</option>
		    <option value="04" <?php if (!(strcmp("04", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>CAMPECHE</option>
		    <option value="05" <?php if (!(strcmp("05", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>COAHUILA</option>
		    <option value="06" <?php if (!(strcmp("06", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>COLIMA</option>
		    <option value="07" <?php if (!(strcmp("07", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>CHIAPAS</option>
		    <option value="08" <?php if (!(strcmp("08", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>CHIHUAHUA</option>
		    <option value="09" <?php if (!(strcmp("09", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>DISTRITO FEDERAL</option>
		    <option value="10" <?php if (!(strcmp("10", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>DURANGO</option>
		    <option value="11" <?php if (!(strcmp("11", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>GUANAJUATO</option>
		    <option value="12" <?php if (!(strcmp("12", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>GUERRERO</option>
		    <option value="13" <?php if (!(strcmp("13", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>HIDALGO</option>
		    <option value="14" <?php if (!(strcmp("14", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>JALISCO</option>
		    <option value="15" <?php if (!(strcmp("15", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>MÉXICO</option>
		    <option value="16" <?php if (!(strcmp("16", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>MICHOACÁN</option>
		    <option value="17" <?php if (!(strcmp("17", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>MORELOS</option>
		    <option value="18" <?php if (!(strcmp("18", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>NAYARIT</option>
		    <option value="19" <?php if (!(strcmp("19", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>NUEVO LEÓN</option>
		    <option value="20" <?php if (!(strcmp("20", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>OAXACA</option>
		    <option value="21" <?php if (!(strcmp("21", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>PUEBLA</option>
		    <option value="22" <?php if (!(strcmp("22", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>QUERÉTARO</option>
		    <option value="23" <?php if (!(strcmp("23", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>QUINTANA ROO</option>
		    <option value="24" <?php if (!(strcmp("24", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>SAN LUIS POTOSÍ</option>
		    <option value="25" <?php if (!(strcmp("25", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>SINALOA</option>
		    <option value="26" <?php if (!(strcmp("26", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>SONORA</option>
		    <option value="27" <?php if (!(strcmp("27", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>TABASCO</option>
		    <option value="28" <?php if (!(strcmp("28", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>TAMAULIPAS</option>
		    <option value="29" <?php if (!(strcmp("29", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>TLAXCALA</option>
		    <option value="30" <?php if (!(strcmp("30", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>VERACRUZ</option>
		    <option value="31" <?php if (!(strcmp("31", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>YUCATÁN</option>
		    <option value="32" <?php if (!(strcmp("32", $row_rsEmpresa['id_cat_entidad']))) {echo "selected=\"selected\"";} ?>>ZACATECAS</option>
	    </select>
		  <span class="selectRequiredMsg">Seleccione un elemento.</span></span></td>
	</tr>
	<tr>
		<td>Municipio </td>
		<td><input name="insMunicipio" type="text" id="insMunicipio" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['gf_municipio']; ?>"></td>
	</tr>
	<tr>
		<td>Localidad, colonia o barrio</td>
		<td><span id="localidad">
		  <input name="insLocalidad" type="text" id="insLocalidad" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['if_localidad']; ?>">
		  <br>
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
		<td>Dirección (Calle y número)</td>
		<td><span id="direccion">
		  <input name="insDireccion" type="text" id="insDireccion" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['id_direccion']; ?>">
		  <br>
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
		<td>C.P.</td>
		<td><span id="cp">
        <input name="insCP" type="text" id="insCP" style="width:280px" onChange="conMayusculas(this)" value="<?php echo $row_rsEmpresa['if_cpostal']; ?>">
        <span class="textfieldRequiredMsg">Se necesita un valor.</span><span class="textfieldMinCharsMsg">No se cumple el mínimo de caracteres requerido.</span><span class="textfieldMaxCharsMsg"><br>
        Se ha superado el número máximo de caracteres.</span></span></td>
	</tr>
	
	<tr>
	  <td colspan="2" style="text-align:right;">&nbsp;</td>
	  </tr>
	<tr>
		<td colspan="2" style="text-align:right;"><input type="submit" class="button" value="Guardar y continuar" onClick="return confirmar('¿Esta seguro que desea registrar los datos ingresados?')"></td>
		</tr>
</table>
<input type="hidden" name="MM_insert" value="formRegCandidato">
<input type="hidden" name="MM_update" value="formUpdateEmpresa">
</form>
</div><!--Container-->

</div><!--Boxcontainer-->
  
   
</center>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur", "change"], minChars:12, maxChars:13, hint:"12 a 13 caracteres"});
var sprytextfield2 = new Spry.Widget.ValidationTextField("rozon_social", "none", {validateOn:["blur", "change"], hint:"Tal como aparece en el formato RFC"});
var sprytextfield3 = new Spry.Widget.ValidationTextField("nombre_comercial", "none", {validateOn:["blur", "change"]});
var sprytextfield4 = new Spry.Widget.ValidationTextField("actividad", "none", {validateOn:["blur", "change"], hint:"Tal como aparece en el formato RFC"});
//
var spryselect2 = new Spry.Widget.ValidationSelect("entidad", {validateOn:["blur", "change"]});
var sprytextfield5 = new Spry.Widget.ValidationTextField("localidad", "none", {validateOn:["blur", "change"]});
var sprytextfield6 = new Spry.Widget.ValidationTextField("direccion", "none", {validateOn:["blur", "change"]});
var sprytextfield7 = new Spry.Widget.ValidationTextField("cp", "none", {validateOn:["blur", "change"], minChars:5, maxChars:5});
</script>
</body>
</html>
<?php
if(isset($rsEmpresa))mysql_free_result($rsEmpresa);

if(isset($rsMunicipio))mysql_free_result($rsMunicipio);

if(isset($rsEmpresas))mysql_free_result($rsEmpresas);
?>
